﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Data.Linq;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using System.Reflection;
using Vit.Common.Extensions;
using Vit.Caching;
using Vit.Web.Data;

namespace Vit.Web.Mvc
{
    public class MetadataTypeAccessor
    {
        protected ICacheManager cache;

        public MetadataTypeAccessor(ICacheManager cache)
        {
            this.cache = cache;
        }

        public MetadataDescriptor GetMetadataDescriptor(Type entityType)
        {
            string key = entityType.AssemblyQualifiedName;
            if(cache != null && cache.Contains(key))
                return cache.GetData(key) as MetadataDescriptor;

            MetadataDescriptor md = new MetadataDescriptor(entityType);
            if(cache != null && cache.Contains(key) == false)
                cache.Add(key, md);

            return md;
        }
    }
}
